package com.cheejee.goodscenter.controller;

import static com.cheejee.goodscenter.module.response.BaseReponse.addOk;
import static com.cheejee.goodscenter.module.response.BaseReponse.deleteOk;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cheejee.goodscenter.module.response.PageReponse;
import com.cheejee.goodscenter.service.SkuSnapshotService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * @author CARRY
 * @Date 2020年11月3日上午3:33:13
 */
@RestController
@RequestMapping("/sku/SkuSnapshot")
@Api(tags = "SKU快照")
public class SkuSnapshotController {

	@Resource
	private SkuSnapshotService service;
	
	@GetMapping("/")
	@ApiOperation("按条件查询SKU快照")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "goodsId", value = "商品ID", dataType = "long"),
		@ApiImplicitParam(name = "skuId", value = "SKU ID", dataType = "long"),
		@ApiImplicitParam(name = "pageSize", value = "每页内容数", defaultValue = "0", dataType = "int"),
		@ApiImplicitParam(name = "pageNum", value = "页码", defaultValue = "0", dataType = "int") })
	public Object getSkuSnapshot(Long goodsId, Long skuId, Integer version, Integer pageNum, Integer pageSize) {
		
		return PageReponse.ok(service.querySkuSnapshot(goodsId, skuId, version, pageNum, pageSize));
	}
	
	@PutMapping("/")
	@ApiOperation(value = "新增SKU快照", notes = "新增某SKU的快照，传入SKU ID。")
	public Object addSkuSnapshot(Long skuId) {
		Long l = service.addSkuSnapshot(skuId);
		
		return addOk(service.querySkuSnapshotById(l));
	}
	
	@DeleteMapping("/{id}")
	@ApiOperation("删除SKU快照")
	public Object deleteSkuSnapshot(@PathVariable Long id) {
		service.deleteSkuSnapshot(id);
		
		return deleteOk();
	}
}
